package com.example.sqliteoperate;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.Nullable;

public class MySqlite extends SQLiteOpenHelper {
    private static Context context;
    private static int version;
    private final static String dbName = "test_sql";
    private static String tableName = "information";
    private static String colName = "name";
    private static String colPrice = "price";

    public static String getTableName() {
        return tableName;
    }

    public static String getColName() {
        return colName;
    }

    public static String getColPrice() {
        return colPrice;
    }

    public MySqlite( Context context, int version) {
        super(context, dbName, null, version);
        this.context = context;
        this.version = version;
        Log.v("life","构造方法");
    }
    public MySqlite(Context context){
        this(context,1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.v("life","onCreate()");
        String sql = "create table "+tableName+" (id integer primary key autoincrement,"+colName+"  varchar(20) ,"+colPrice+" integer)";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
